import Vue from 'vue';
import Vuex from 'vuex';
import router, {staticRoutes} from '@/router';

Vue.use(Vuex);

export default new Vuex.Store({
  state: {
    routerList: staticRoutes,
  },
  getters: {
    routeList: state => state.routerList,
  },
  mutations: {
    SET_ROUTER: (state, RouterList) => {
      state.routerList = RouterList;
    },
  },
  actions: {
    set_router({state, commit}, routerList) {
      routerList.forEach(t => router.addRoute(t));
      commit('SET_ROUTER', state.routerList.concat(routerList));
    },
  },
  modules: {},
});
